package models

import (
	"fmt"
	"gorm.io/gorm"
)

// ProPermission 项目权限表
type ProPermission struct {
	ID             uint64 `gorm:"primaryKey;autoIncrement" json:"id" form:"id"`
	PermissionName string `gorm:"type:varchar(255);notNull;uniqueIndex:idx_pro_permission_name" json:"permission_name" form:"permission_name"`
	Description    string `gorm:"type:text" json:"description" form:"description"`
	CreatedAt      string `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"created_at" form:"created_at"`
	UpdatedAt      string `gorm:"type:timestamp;default:CURRENT_TIMESTAMP;update:CURRENT_TIMESTAMP" json:"updated_at" form:"updated_at"`
}

func (ProPermission) TableName() string {
	return "pro_permissions"
}

//	GetPermissionsDetailsByIDSlice
//
// 描述信息：根据权限ID切片获取权限详细信息
//
// Param：
//
//	db ：数据库连接实例
//	permissionIDs ：权限id切片
//
// Return：
//
//	[]ProPermission ：权限信息切片
//	error ：错误信息
func GetPermissionsDetailsByIDSlice(db *gorm.DB, permissionIDs []uint64) ([]ProPermission, error) {
	var permissions []ProPermission
	if err := db.Model(&ProPermission{}).Where("id IN ?", permissionIDs).Find(&permissions).Error; err != nil {
		return nil, fmt.Errorf("failed to query permissions details: %w", err)
	}
	return permissions, nil
}
